package com.mlz.controller;

import com.mlz.pojo.Result;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class SessionController {

    @GetMapping("/s1")
    public Result session1(HttpSession session) {
        log.info("HttpSession-s1:{}", session.hashCode());

        //往session中存储数据
        session.setAttribute("loginUser","lucy");
        return Result.success();
    }


    @GetMapping("/s2")
    public Result session2(HttpServletRequest request) {
        HttpSession session = request.getSession();
        log.info("HttpSession-s2:{}", session.hashCode());

        //往session中获取
        Object loginUser = session.getAttribute("loginUser");
        log.info("loginUser:{}",loginUser);
        return Result.success(loginUser);
    }
}
